@echo off

rem 根据最新代码构建新的镜像
docker build -t nsjava:v2 .

rem 创建新的Deployment和Service
kubectl apply -f k8s-dev-v2.yaml
kubectl apply -f k8s-service-v2.yaml

rem 逐步将流量从旧的版本转移到新的版本上
for /l %%i in (1,1,3) do (
  kubectl patch deployment nsjava -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"%%TIME:~0,2%%%%TIME:~3,2%%%%TIME:~6,2%%\"}}}}}"
  timeout /t 10
)

rem 删除旧的Deployment和Service
kubectl delete deployment nsjava
kubectl delete service nsjava
